<?php
class GoogleHelper extends AppHelper {
	
	public function __get($script){
		switch ($script){
			case 'analytics':
				$path = Configure::read('Config.google.path');
				$file = Configure::read('Config.google.analytics');
				$script = $this->read($path, $file);
				break;
			case 'apikey':
				$path = Configure::read('Config.google.path');
				$file = Configure::read('Config.google.apikey');
				$script = $this->read($path, $file);
				break;				
		}
		return $script;
	}
	
	private function read($path,$file){
		$kod = '';
		if(!is_dir($path)) @mkdir($path);
		if(is_file($path.$file)){	
			$fh = fopen($path.$file, 'r+');
			$size = filesize($path.$file);
			if ($size != 0) $kod = fread($fh,$size);			
		}else{
			$fh = fopen($path.$file, 'a+');
			$kod = '';
		}
		fclose($fh);
		$kod = stripcslashes($kod);
		return $kod;		
	}
}